from fastapi import FastAPI
from fastapi.middleware.cors import CORSMiddleware
import uvicorn

# 绝对导入
from app.routers import chat, system
from app.config import settings

app = FastAPI(
    title="AI Chat API",
    description="A powerful AI chat application API",
    version="1.0.0"
)

# CORS middleware
app.add_middleware(
    CORSMiddleware,
    allow_origins=settings.ALLOWED_ORIGINS,
    allow_credentials=True,
    allow_methods=["*"],
    allow_headers=["*"],
)

# Include routers
app.include_router(chat.router, prefix="/api/v1", tags=["chat"])
app.include_router(system.router, prefix="/api/v1", tags=["system"])

@app.get("/")
async def root():
    return {"message": "AI Chat API is running", "version": "1.0.0"}

@app.get("/health")
async def health_check():
    return {"status": "healthy"}

if __name__ == "__main__":
    uvicorn.run(
        "app.main:app",
        host=settings.HOST,
        port=settings.PORT,
        reload=settings.DEBUG
    )